<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script type="text/babel">
    class DemoA extends React.Component {
        constructor(props) {
            super(props)
        }
        render() {
            return (
                <div>
                <p>子组件1---{this.props.msg}</p>
                    </div>
            )
    }B
    }

    class DemoB extends React.Component {
        constructor(props) {
            super(props)
        }
        render() {
            return (
                <div>
                <p>子组件2---{this.props.msg}</p>
                    </div>
            )
    }
    }

    class MyDom extends React.Component {

        constructor(props) {
            super(props)
            this.state = {
                name: '张三'
            }
        }

        changName = () => {
            this.setState({
                name: '李四'
            }, () => {
                console.log(this.state.name);
            })
            console.log(this.state.name);
        }
       

        render() {
            return (<div>
               
                <button onClick={this.changName}>按钮</button>
              
                <DemoA msg={this.state.name}/>
                <DemoB msg={this.state.name}/>
            </div>
            )
        }
    }


    ReactDOM.render(<MyDom />, document.getElementById('app'))
</script>

</html>